package com.scau402.system1.controller;

import com.scau402.common.core.controller.BaseController;
import com.scau402.common.core.domain.AjaxResult;
import com.scau402.common.core.page.TableDataInfo;
import com.scau402.system1.domain.dto.AuditOrderDTO;
import com.scau402.system1.domain.po.WmsAuditOrderPO;
import com.scau402.system1.domain.query.AuditOrderQuery;
import com.scau402.system1.domain.query.WmsAdjustBoundOrderQuery;
import com.scau402.system1.service.IWmsAuditOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * 审核模块控制器
 * @since 2024/2/5
 */
@RestController
@RequestMapping("/system/audit")
@Slf4j
public class WmsAuditOrderController extends BaseController {
    @Autowired
    private IWmsAuditOrderService wmsAuditOrderService;

    /**
     * 获取审核单列表
     * @param type 审核类型：0：价格调整、1：出借天数、2：库存调整、3：入库数量
     * @return 审核单列表
     * @since 2024/2/5
     */
    @GetMapping("/list")
    public TableDataInfo listAuditOrder(@RequestParam
                                     @NotNull(message = "审核类型不能为空!")
                                     @NotBlank(message = "审核类型不能为空!")
                                     String type,@RequestBody(required = false) WmsAdjustBoundOrderQuery auditOrderQuery){

        switch (type) {
            //入库
            case "3":{
                return wmsAuditOrderService.listInboundAuditOrder();
            }
            //库存调整
            case "2" : {
                return wmsAuditOrderService.listAdjustboundAuditOrder(auditOrderQuery);
            }
            //长期出借出库调整
            case "1" : {
                return wmsAuditOrderService.listOutboundAuditOrder();
            }
            //价格调整
            case "0" : {
                return wmsAuditOrderService.listPriceAdjustAuditOrder(auditOrderQuery);
            }
        }
        log.warn("审核操作：未知审核类型：{}",type);
        return null;
    }


    /**
     * 获取入库审核单列表
     * @return 审核单列表
     * @since 2024/2/19
     */
    @PreAuthorize("@ss.hasPermi('system:audit:query:inbound')")
    private TableDataInfo listInboundAuditOrder() {
        return wmsAuditOrderService.listInboundAuditOrder();
    }

    /**
     * 获取价格调整审核单列表
     * @return 审核单列表
     * @since 2024/2/15
     */
    @PreAuthorize("@ss.hasPermi('system:audit:query:adjustPrice')")
    private TableDataInfo listPriceAdjustAuditOrder(WmsAdjustBoundOrderQuery auditOrderQuery) {
        return wmsAuditOrderService.listPriceAdjustAuditOrder(auditOrderQuery);
    }

    /**
     * 获取库存调整审核单列表
     * @return 审核单列表
     * @since 2024/2/15
     */
    @PreAuthorize("@ss.hasPermi('system:audit:query:adjustBound')")
    private TableDataInfo listAdjustboundAuditOrder(WmsAdjustBoundOrderQuery auditOrderQuery) {
        return wmsAuditOrderService.listAdjustboundAuditOrder(auditOrderQuery);
    }

    /**
     * 获取长期出借出库审核单列表
     * @return 审核单列表
     * @since 2024/2/15
     */
    @PreAuthorize("@ss.hasPermi('system:audit:query:outbound')")
    public TableDataInfo listOutboundAuditOrder(){
        return wmsAuditOrderService.listOutboundAuditOrder();
    }

    /**
     * 批量审核操作
     * @param auditOrderDTO 审核动作DTO
     * @return
     * @since 2024/2/5
     */
    @PreAuthorize("@ss.hasPermi('system:audit:audit')")
    @PostMapping
    public AjaxResult audit(@RequestBody @Validated AuditOrderDTO auditOrderDTO){
        return wmsAuditOrderService.audit(auditOrderDTO);
    }

    /**
     * 创建审核单
     * @param type 审核类型：0：价格调整、1：出借天数、2：库存调整
     * @param id 发起单id——如库存调整单id/出库单id/价格调整单id等
     * @since 2024/2/5
     */
    public void create(String type,Long id){
        wmsAuditOrderService.create(type,id);
    }
}
